package com.pbking.util.logging.bridges
{
	import com.pbking.util.logging.PBLogEvent;
	import com.pbking.util.logging.PBLogLevel;
	import com.pbking.util.logging.PBLogger;
	import com.pbking.util.logging.bridges.util.ArthropodDebug;
	
	/**
	 * Passes all logs on to the ArthropodLogger framework
	 * This allows you to use the PBLogger framework for
	 * logging and also pass those logs on to the Arthropod
	 * log viewer.  You should call the public static method
	 * initialize() only once per application to create the
	 * bridge.
	 * <br/>
	 * usage:<br/><code>
	 * PBLogArthropodBridge.initialize();
	 * PBLogger.getLogger("test").debug("my debug message");
	 * </code>
	 */
	public class PBLogArthropodBridge
	{
		private static var initialized:Boolean = false;

		// CONSTRUCTION //////////

		public function PBLogArthropodBridge()
		{
		}
		
		public static function initialize(password:String=null):void
		{
			if(!initialized)
			{
				PBLogger.addEventListener(PBLogEvent.LOG, onPbLog);
				
				ArthropodDebug.password = password;

				initialized = true;
			}
		}
		
		private static function onPbLog(event:PBLogEvent):void
		{
			switch (event.level)
			{
				case PBLogLevel.DEBUG:
					ArthropodDebug.log(event.toString());
					break;
					
				case PBLogLevel.INFO:
					ArthropodDebug.log(event.toString(), ArthropodDebug.GREEN);
					break;
					
				case PBLogLevel.ERROR:
					ArthropodDebug.log(event.toString(), ArthropodDebug.BLUE);
					break;
					
				case PBLogLevel.WARN:
					ArthropodDebug.log(event.toString(), ArthropodDebug.PINK);
					break;
					
				case PBLogLevel.FATAL:
					ArthropodDebug.log(event.toString(), ArthropodDebug.RED);
					break;
					
			}
		}

	}
}